<?php
/**
 * Created by PhpStorm.
 * User: edmmss
 * Date: 2019/1/9
 * Time: 14:14
 */

namespace app\modules\specification;


class PriceSpecification implements SpecificationInterface
{
    private $_maxPrice;

    private $_minPrice;

    public function __construct($minPrice, $maxPrice)
    {
        $this->_minPrice = $minPrice;
        $this->_maxPrice = $maxPrice;
    }

    /**
     * className
     *
     * @date   2019/1/9
     * @author edmmss
     * @param Item $item
     * @return bool
     */
    public function isSatisfiedBy(Item $item): bool
    {
        // TODO: Implement isSatisfiedBy() method.
        if (($this->_maxPrice !== null && $item->getPrice() > $this->_maxPrice)
            || ($this->_minPrice !== null && $item->getPrice() < $this->_minPrice)) {
            return false;
        }

        return true;
    }
}